using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
namespace LabMS.Web.ProjectApp
{
    public partial class TeachReformPreview : Base.BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                DataBinds();
            }
        }

        protected string QueryString 
        {
            get { return Request.QueryString["ID"].ToString(); }
        }
        protected void DataBinds() 
        {
            LabMS.BLL.TeachingReform Reform = new LabMS.BLL.TeachingReform();
            LabMS.Model.TeachingReform model = Reform.GetModel(Convert.ToInt32( QueryString));
            

            LabMS.BLL.DictionaryClass DicClass = new LabMS.BLL.DictionaryClass();
            LabMS.BLL.Dictionary Dic = new LabMS.BLL.Dictionary();
            LabMS.Model.DictionaryClass ds = new LabMS.Model.DictionaryClass();
            List<LabMS.Model.Dictionary> ls = new List<LabMS.Model.Dictionary>();

            if (DicClass.GetModelList("Code='TeachingReform'").Count != 0) 
            {
                ds = DicClass.GetModelList("Code='TeachingReform'")[0];
                ls = Dic.GetModelList("DClass='" + ds.Code + "'");
                if (ls.Count != 0) 
                {
                    ddl_ProjectType.DataSource = ls;
                    ddl_ProjectType.DataTextField = "Name";
                    ddl_ProjectType.DataValueField = "Code";
                    ddl_ProjectType.DataBind();
                    if (!string.IsNullOrEmpty(model.Teach_DocType))
                    {
                        ddl_ProjectType.Items.FindByValue(model.Teach_DocType).Selected = true;
                    }
                }
            }

            tb_Addres.Text = model.Teach_Address;
            tb_Email.Text = model.Teach_Mail;
            tb_InCharge.Text = model.Teach_InCharge;
            tb_Phone.Text = model.Teach_Phone;
            tb_UnitName.Text = model.Teach_UnitName;
            tb_ProjectName.Text = model.Teach_ProjectName;

            if (DicClass.GetModelList("Code='UnitType'").Count > 0) 
            {
                ds = DicClass.GetModelList("Code='UnitType'")[0];
                ls = Dic.GetModelList("DClass='" + ds.Code + "'");
                if (ls.Count > 0) 
                {
                    rbl_UnitType.DataSource = ls;
                    rbl_UnitType.DataTextField = "Name";
                    rbl_UnitType.DataValueField = "Code";
                    rbl_UnitType.DataBind();
                    if (!string.IsNullOrEmpty(model.Teach_UnitType))
                    {
                        rbl_UnitType.Items.FindByValue(model.Teach_UnitType).Selected = true;
                    }
                }
            }
            
        }

        protected void Submit_Click(object sender, EventArgs e)
        {
            LabMS.BLL.TeachingReform Reform = new LabMS.BLL.TeachingReform();
            LabMS.Model.TeachingReform model = new LabMS.Model.TeachingReform();
            model = Reform.GetModel(Convert.ToInt32(QueryString));

            model.Teach_ProjectName = tb_ProjectName.Text;
            model.Teach_Address = tb_Addres.Text;
            model.Teach_InCharge = tb_InCharge.Text;
            model.Teach_Mail = tb_Email.Text;
            model.Teach_ProjectName = tb_ProjectName.Text;
            model.Teach_UnitName = tb_UnitName.Text;
            model.Teach_UnitType = rbl_UnitType.SelectedValue;
            model.Teach_Phone = tb_Phone.Text;
            model.Teach_Time = DateTime.Now;
            model.Teach_DocType = ddl_ProjectType.SelectedValue.Trim();

            Reform.Update(model);
            Response.Redirect(@"\ProjectApp\TeachingReformList.aspx");
        }

    }
}
